package ywpt.components.acegi.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;



import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import ywpt.model.PeopleInfo;


public class User implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long	serialVersionUID	= -5011010829859035170L;
	private Long				id;
	private Integer				version;
	private String				username;
	private String				password;
	private String				confirmPassword;
	private String				passwordHint;
	private String				pin;
	private String				fullName;
	private String 				organName;
	private String				gender;
	private PeopleInfo          people;
	private boolean				enabled;
	private boolean				accountExpired;
	private boolean				accountLocked;
	private boolean				credentialsExpired;
	private String				description;
	private Set<Role>			roles				= new HashSet<Role>(0);

	private String  positionName;
	public String getPositionName() {
		return people.getPosition().getPositionName();
	}


	// Constructors
	/** default constructor */
	public User() {
	}

	/** minimal constructor */
	public User(Long id) {
		this.id = id;
	}

	/** full constructor */
	public User(String username, String password, String confirmPassword, String passwordHint, String pin, String fullName, String gender,
			 boolean enabled, boolean accountExpired, boolean accountLocked, boolean credentialsExpired, String description) {
		this.username = username;
		this.password = password;
		this.confirmPassword = confirmPassword;
		this.passwordHint = passwordHint;
		this.pin = pin;
		this.fullName = fullName;
		this.enabled = enabled;
		this.accountExpired = accountExpired;
		this.accountLocked = accountLocked;
		this.credentialsExpired = credentialsExpired;
		this.description = description;
	}

	// Property accessors
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConfirmPassword() {
		return this.confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public String getPasswordHint() {
		return this.passwordHint;
	}

	public void setPasswordHint(String passwordHint) {
		this.passwordHint = passwordHint;
	}

	public String getPin() {
		return this.pin;
	}

	public void setPin(String pin) {
		this.pin = pin;
	}

	public String getFullName() {
		return this.fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public boolean isEnabled() {
		return this.enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public boolean isAccountExpired() {
		return this.accountExpired;
	}

	public boolean isAccountNonExpired() {
		return !isAccountExpired();
	}

	public void setAccountExpired(boolean accountExpired) {
		this.accountExpired = accountExpired;
	}

	public boolean isAccountLocked() {
		return this.accountLocked;
	}

	public void setAccountLocked(boolean accountLocked) {
		this.accountLocked = accountLocked;
	}

	public boolean isAccountNonLocked() {
		return !isAccountLocked();
	}

	public boolean isCredentialsExpired() {
		return this.credentialsExpired;
	}

	public void setCredentialsExpired(boolean credentialsExpired) {
		this.credentialsExpired = credentialsExpired;
	}

	public boolean isCredentialsNonExpired() {
		return !credentialsExpired;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public void addRole(Role role) {
		getRoles().add(role);
	}

	public void removeRole(Role role) {
		getRoles().remove(role);
	}


	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof User)) {
			return false;
		}
		final User user = (User) o;
		if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		return (username != null ? username.hashCode() : 0);
	}

	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("username", username).append("enabled", enabled).append(
				"accountExpired", accountExpired).append("credentialsExpired", credentialsExpired).append("accountLocked", accountLocked);
		
		return sb.toString();
	}


	public PeopleInfo getPeople() {
		return people;
	}

	public void setPeople(PeopleInfo people) {
		this.people = people;
	}

	public String getOrganName() {
		return organName;
	}

	public void setOrganName(String organName) {
		this.organName = organName;
	}
}